Background

Late in December 2019, the World Health Organisation (WHO) China Country Office obtained information about a severe pneumonia of an unknown cause, detected in the city of Wuhan in Hubei province, China. This later turned out to be the novel coronavirus disease (COVID-19), an infectious disease caused by severe acute respiratory syndrome coronavirus-2 (SARS-CoV-2) of the corona virus family. The disease causes respiratory illness characterised by primary symptoms like cough, fever, and in more acute cases, difficulty in breathing. WHO later declared covid-19 as a Pandemic because of its fast rate of spread across the Globe with over 5.69 Million confirmed cases and over 355,000 deaths as of May 28, 2020. The African continent started confirming its first cases in late January and mid-February of 2020 in some countries. The disease has since spread across all the 54 Africa countries with over 124,000 confirmed cases and over 3,600 deaths as of May 28, 2020.

The Dataset

The covid_19_africa.csv dataset contains daily level information about the Covid-19 cases in Africa. It is a time series data and hence the number of cases on any given day is cumulative.I extracted the data from the covid_19_data.csv which was made available on kaggle. The R script that I used to prepare this dataset is also available on my Github repository. The original datasets can be found on John Hopkins University Github repository for covid_19.

Field description

  • ObservationDate: YY/MM/DD
  • Country: name of African country
  • Region: Region of the African country
  • Confirmed: the number of cOVID-19 confirmed cases
  • Deaths: the number of deaths from COVID-19
  • Recovered: the number of recovered cases
  • Active: the number of people still infected with COVID-19

Task

Visualizations of Africa’s COVID-19 cases.

Data processing

# loading the required packages
suppressMessages(library(tidyverse))
## Warning: package 'ggplot2' was built under R version 3.6.3
suppressMessages(library(lubridate))
suppressMessages(library(DT))
## Warning: package 'DT' was built under R version 3.6.3
suppressMessages(library(highcharter))
## Warning: package 'highcharter' was built under R version 3.6.3
suppressMessages(library(htmltools))

# importing the dataset
covid_africa <- read_csv("covid_19_africa.csv")

# converting the classes of Confirmed, Deaths, and Recovered columns to class integer
covid_africa <- covid_africa %>%
        
        mutate(Region = as_factor(Region),
               Confirmed = as.integer(Confirmed), 
               Deaths = as.integer(Deaths),
               Recovered = as.integer(Recovered),
               Active = as.integer(Active))
knitr::opts_chunk$set(message = FALSE, warning = FALSE)

COVID-19 in Africa

A summary of COVID-19 cases in Africa since 27th of January, 2020

Note that the lastest number of cases are those reported by end of the previous day.

datatable(covid_africa)

Number of African countries with confirmed cases

length(unique(covid_africa$Country))
## [1] 54

All the 54 African countries recognized by the UN and WHO have confirmed cases of COVID-19.

Cumulative number of COVID-19 cases in Africa

Note: all plots with legends can be activated or deactivated by clicking on the legend.

# obtaining the cumulative cases by observation date
cases <- covid_africa %>%
        group_by(ObservationDate) %>%
        summarise(Confirmed = sum(Confirmed), Deaths = sum(Deaths), 
                  Recovered = sum(Recovered), Active = sum(Active))

# specifying the plot colors
colors <- c("Active" = "cyan", "Confirmed" = "orange", "Deaths" = "red", "Recovered" = "lightseagreen")

# plotting
cases %>%
        gather(Confirmed, Deaths, Recovered, Active, key = "cases", value = "number") %>%
        hchart("line", hcaes(x = ObservationDate, y = number, group = cases),
               color = colors) %>%
        hc_title(text = "Cumulative number of COVID-19 cases in Africa") %>%
        hc_subtitle(text = today()) %>%
        hc_xAxis(title = list(text = "Date")) %>%
        hc_yAxis(title = list(text = "Number of cases")) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
        hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
        hc_add_theme(hc_theme_google())

Daily new confirmed cases and new deaths from COVID-19 in Africa

# computing the daily new cases and deaths
new_cases <- cases %>%
        mutate(new_confirmed = Confirmed - lag(Confirmed, default = first(Confirmed)),
               new_deaths = Deaths - lag(Deaths, default = first(Deaths))) %>%
        select(ObservationDate, new_confirmed, new_deaths)

# specifying the plot colors
new_colors <- c("new_confirmed" = "orange", "new_deaths" = "red")

# plotting
new_cases %>%
        gather(new_confirmed, new_deaths, 
               key = "cases", value = "number") %>%
        hchart("column", hcaes(x = ObservationDate, y = number, group = cases),
               color = new_colors) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
        hc_xAxis(title = list(text = "Date")) %>%
        hc_yAxis(title = list(text = "Number of cases")) %>%
        hc_add_theme(hc_theme_google()) %>%
        hc_title(text = "Daily new cases and deaths from COVID-19 in Africa") %>%
        hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
        hc_subtitle(text = today())

Case Fatality Rate(%) and Recovery Rate(%) from COVID-19 in Africa

The case fatality rate and recovery rate are dependant on accurate reporting of COVID-19 cases. The limited testing capacities of some African countries implies that these values may be inexact.

# computing the rates
rates <- cases %>%
  mutate(case_fatality = (Deaths / Confirmed) * 100,
         recovery_rate = (Recovered / Confirmed) * 100,
         CFR = round(case_fatality, 2),
         RR = round(recovery_rate, 2))

# specifying the colors
rates_color <- c("CFR" = "red", "RR" = "lightgreen")

# plotting
rates %>% 
  gather(CFR, RR, key = "cases", value = "number") %>%
  hchart("line", hcaes(x = ObservationDate, y = number, group = cases),
         color = rates_color) %>%
  hc_xAxis(title = list(text = "Date")) %>%
  hc_yAxis(title = list(text = "Percent(%)")) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_title(text = "Changes in the Case Fatality Rate(CFR) and Recovery Rate(RR) in Africa") %>%
  hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
  hc_add_theme(hc_theme_google())

Heatmaps of Africa showing COVID-19 cases

# getting the latest number of cases of COVID-19 in Africa by country
latest <- covid_africa %>%
        filter(ObservationDate == today() - 1 )

# downloading a map of Africa
africa_map <- download_map_data("https://code.highcharts.com/mapdata/custom/africa.js")

# looking and the African Countries
properties <- get_data_from_map(africa_map)

# modify some country names in the covid_19_africa data to match those in africa_map
latest_1 <-  latest %>%
        mutate(Country = replace(Country, Country == "Congo (Kinshasa)", "Democratic Republic of the Congo"),
               Country = replace(Country, Country == "Congo (Brazzaville)", "Republic of Congo"),
               Country = replace(Country, Country == "Tanzania", "United Republic of Tanzania"))

Confirmed

highchart() %>%
        hc_add_series_map(africa_map, latest_1, value = "Confirmed",
                          joinBy = c("name", "Country"), name = "Confirmed") %>%
        hc_colorAxis(minColor = "lightyellow", maxColor = "Darkorange") %>%
        hc_mapNavigation(enabled = TRUE) %>%
        hc_title(text = "Confirmed") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1)

Deaths

highchart() %>%
        hc_add_series_map(africa_map, latest_1, value = "Deaths",
                          joinBy = c("name", "Country"), name = "Deaths") %>%
        hc_colorAxis(minColor = "snow", maxColor = "darkred") %>%
        hc_mapNavigation(enabled = TRUE) %>%
        hc_title(text = "Deaths") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1)

Recovered

highchart() %>%
  hc_add_series_map(africa_map, latest_1, value = "Recovered",
                    joinBy = c("name", "Country"), name = "Recovered") %>%
  hc_colorAxis(minColor = "lightgreen", maxColor = "darkgreen") %>%
  hc_mapNavigation(enabled = TRUE) %>%
  hc_title(text = "Recovered") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1)

Active

highchart() %>%
  hc_add_series_map(africa_map, latest_1, value = "Active",
                    joinBy = c("name", "Country"), name = "Active") %>%
  hc_colorAxis(minColor = "lightcyan", maxColor = "darkcyan") %>%
  hc_mapNavigation(enabled = TRUE) %>%
  hc_title(text = "Active") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1)

COVID-19 cases by African Region

Cumulative number of COVID-19 cases by African Region

# computing the regional cases of COVID-19
regional_cases <- covid_africa %>%
        group_by(ObservationDate, Region) %>%
        summarise(Confirmed = sum(Confirmed), Deaths = sum(Deaths),
                  Recovered = sum(Recovered), Active = sum(Active))

Confirmed

# plotting
regional_cases %>%                  
hchart("line", hcaes(x = ObservationDate, y = Confirmed, group = Region)) %>%
        hc_xAxis(title = list(text = "Date")) %>%       
        hc_title(text = "Cumulative Confirmed cases") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
        hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
        hc_add_theme(hc_theme_google())

Deaths

regional_cases %>%                  
        hchart("line", hcaes(x = ObservationDate, y = Deaths, group = Region)) %>%
        hc_xAxis(title = list(text = "Date")) %>%      
        hc_title(text = "Cumulative Deaths") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
        hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
        hc_add_theme(hc_theme_google())

Recovered

regional_cases %>%                  
  hchart("line", hcaes(x = ObservationDate, y = Recovered, group = Region)) %>%
  hc_xAxis(title = list(text = "Date")) %>%      
  hc_title(text = "Cumulative Recoveries") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_add_theme(hc_theme_google())

Active

regional_cases %>%                  
  hchart("line", hcaes(x = ObservationDate, y = Active, group = Region)) %>%
  hc_xAxis(title = list(text = "Date")) %>%      
  hc_title(text = "Cumulative Active cases") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_add_theme(hc_theme_google())

Case Fatality Rate(%) and Recovery Rate(%)

# computing the regional CFR and RR
regional_rates <- latest %>%
  group_by(Region) %>%
  summarise(Confirmed = sum(Confirmed), Deaths = sum(Deaths), Recovered = sum(Recovered)) %>%
  mutate(case_fatality = (Deaths / Confirmed) * 100,
         fatality_rounded = round(case_fatality, 2),
         recovery_rate = (Recovered / Confirmed) * 100,
         recovery_rounded = round(recovery_rate, 2))
  
# plotting
regional_fatality <- regional_rates %>%
  arrange(case_fatality) %>%
  hchart("column", hcaes(Region, fatality_rounded), color = "red", name = "CFR(%)") %>%
  hc_yAxis(title = list(text = "Case Fatality Rate (%)")) %>%
  hc_title(text = "Case Fatality Rate by African Region") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_add_theme(hc_theme_google())

regional_recovery <- regional_rates %>%
  arrange(recovery_rate) %>%
  hchart("column", hcaes(Region, recovery_rounded), color = "green", name = "RR(%)") %>%
  hc_yAxis(title = list(text = "Recovery Rate (%)")) %>%
  hc_title(text = "Recovery Rate by African Region") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_add_theme(hc_theme_google())

# all plots on same page
all_rates <- list(regional_fatality, regional_recovery)
hw_grid(all_rates, rowheight = 400, ncol = 2) %>% browsable()

COVID-19 cases by African Country

Highest to the Lowest: the number of COVID-19 cases in Africa by Country

# getting the latest number of confirmed cases in descending order
latest_confirmed <- latest %>%
        arrange(desc(Confirmed))

Confirmed

# plotting       
highchart() %>% 
        hc_add_series(data = latest_confirmed, type = "bar",
                      hcaes(x = Country, y = Confirmed),
                      name = "Confirmed cases", showInLegend = FALSE,
                      color = "orange") %>%
        hc_xAxis(categories = latest_confirmed$Country,
                 title = list(text = "Country")) %>%
        hc_yAxis(title = list(text = "Confirmed cases")) %>%
        hc_title(text = "COVID-19 Confirmed cases by African Country") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
        hc_size(900, 900)

Deaths

# COVID-19 deaths in descending order
latest_deaths <- latest %>%
        arrange(desc(Deaths))

# plotting       
highchart() %>% 
        hc_add_series(data = latest_deaths, type = "bar",
                      hcaes(x = Country, y = Deaths),
                      name = "Deaths", showInLegend = FALSE,
                      color = "red") %>%
        hc_xAxis(categories = latest_deaths$Country,
                 title = list(text = "Country")) %>%
        hc_yAxis(title = list(text = "Deaths")) %>%
        hc_title(text = "Deaths from COVID-19 by Country") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
        hc_size(900, 900)

Recovered

# recovered cases in descending order
latest_recovered <- latest %>%
        arrange(desc(Recovered))

# plotting       
highchart() %>% 
        hc_add_series(data = latest_recovered, type = "bar",
                      hcaes(x = Country, y = Recovered),
                      name = "Recovered cases", showInLegend = FALSE,
                      color = "lightseagreen") %>%
        hc_xAxis(categories = latest_recovered$Country,
                 title = list(text = "Country")) %>%
        hc_yAxis(title = list(text = "Recovered cases")) %>%
         hc_title(text = "COVID-19 recoveries by Country") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
        hc_size(900, 900)

Active

# active cases in ascending order
latest_active <- latest %>%
        arrange(desc(Active))

# plotting       
highchart() %>% 
        hc_add_series(data = latest_active, type = "bar",
                      hcaes(x = Country, y = Active),
                      name = "Active cases", showInLegend = FALSE,
                      color = "cyan") %>%
        hc_xAxis(categories = latest_active$Country,
                 title = list(text = "Country")) %>%
        hc_yAxis(title = list(text = "Active cases")) %>%
        hc_title(text = "Active cases of COVID-19 in Africa by Country") %>%
        hc_subtitle(text = today()) %>%
        hc_chart(borderColor = "grey",
                 borderWidth = 1) %>%
        hc_size(900, 900)

Case Fatality Rate(%) and Recovery Rate(%) in Each African Country

latest %>%
  mutate(case_fatality = (Deaths / Confirmed) * 100,
         fatality_rounded = round(case_fatality, 2),
         recovery_rate = (Recovered / Confirmed) * 100,
         recovery_rounded = round(recovery_rate, 2)) %>%
  rename("Case Fatality Rate(%)" = fatality_rounded,
         "Recovery Rate(%)" = recovery_rounded) %>%
  select(Country, Region, "Case Fatality Rate(%)", "Recovery Rate(%)") %>%
  datatable()

Compare countries of Choice

Confirmed

Compare the changes in the number of COVID-19 cases in your countries of choice

covid_africa %>%
hchart("spline", hcaes(ObservationDate, Confirmed, group = Country), visible = FALSE) %>%
  hc_xAxis(title = list(text = "Date")) %>%      
  hc_title(text = "Confirmed cases") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_add_theme(hc_theme_google()) %>%
  hc_size(800, 600)

Deaths

Compare changes in the number of COVID-19 deaths in your countries of choice

covid_africa %>%
  hchart("spline", hcaes(ObservationDate, Deaths, group = Country), visible = FALSE) %>%
  hc_xAxis(title = list(text = "Date")) %>%      
  hc_title(text = "Deaths") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_add_theme(hc_theme_google()) %>%
  hc_size(800, 600)

Recovered

Compare changes in the number of COVID-19 recoveries in your countries of choice

covid_africa %>%
  hchart("spline", hcaes(ObservationDate, Recovered, group = Country),
         visible = FALSE) %>%
  hc_xAxis(title = list(text = "Date")) %>%      
  hc_title(text = "Deaths") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_add_theme(hc_theme_google()) %>%
  hc_size(800, 600)

Active

Compare changes in the number of COVID-19 Active cases in your countries of choice

covid_africa %>%
  hchart("spline", hcaes(ObservationDate, Active, group = Country),
         visible = FALSE) %>%
  hc_xAxis(title = list(text = "Date")) %>%      
  hc_title(text = "Active") %>%
  hc_subtitle(text = today()) %>%
  hc_chart(borderColor = "grey",
           borderWidth = 1) %>%
  hc_tooltip(crosshairs = TRUE, sort = TRUE, table = TRUE) %>%
  hc_add_theme(hc_theme_google()) %>%
  hc_size(800, 600)

References

  1. John Hopkins University Covid_19 datasets: https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_daily_reports
  2. SRk’s dataset on kaggle: https://www.kaggle.com/sudalairajkumar/novel-corona-virus-2019-dataset#covid_19_data.csv
  3. African Arguments, Covid-19 Africa Tracker: https://africanarguments.org/2020/04/07/coronavirus-in-africa-tracker-how-many-cases-and-where-latest/